package com.rr.sc.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(HttpServletRequest request) throws Exception {
	Authentication auth = SecurityContextHolder.getContext().getAuthentication();
	if (auth != null) {
	    System.out.println(auth.getName());
	    System.out.println(auth.getAuthorities());
	    System.out.println(auth.isAuthenticated());
	    System.out.println(auth.getCredentials());
	    System.out.println(auth.getPrincipal());
	} else {
	    System.out.println("NOT AUTHENTICATED");
	}

	return "home";
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
	Authentication auth = SecurityContextHolder.getContext().getAuthentication();
	if (auth == null) {
	    return "login";
	} else {
	    return "home";
	}
    }
}
